package com.cl.blog.config;

import com.cl.blog.web.client.task.LikeTask;
import com.cl.blog.web.client.task.RankTask;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author 付
 * @Date 2024-04-02 12:21
 * @Version 1.0
 * @description 定时任务配置
 * @since 1.0
 */
@Configuration
public class QuartzConfig {
	@Bean
	public JobDetail quartzDetail_1() {
		// withIdentity指定的是这个job的id
		return JobBuilder.newJob(LikeTask.class).withIdentity("LIKE_TASK_IDENTITY").storeDurably().build();
	}

	@Bean
	public Trigger quartzTrigger_1() { //触发器
		SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
//				.withIntervalInSeconds(20)  //设置时间周期单位秒
				.withIntervalInHours(2)  //两个小时执行一次
				.repeatForever();
		return TriggerBuilder.newTrigger().forJob(quartzDetail_1())
//                .forJob(quartzDetail_2())
				.withIdentity("USER_TRENDS_TRIGGER")
				.withSchedule(scheduleBuilder)
				.build();
	}

	@Bean
	public JobDetail quartzDetail_2() {
		// withIdentity指定的是这个job的id
		return JobBuilder.newJob(RankTask.class).withIdentity("RANK_TASK_IDENTITY").storeDurably().build();
	}

	@Bean
	public Trigger quartzTrigger_2() { //触发器
		SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
//				.withIntervalInSeconds(20)  //设置时间周期单位秒
				.withIntervalInHours(24)  //两个小时执行一次
				.repeatForever();
		return TriggerBuilder.newTrigger().forJob(quartzDetail_2())
//                .forJob(quartzDetail_2())
				.withIdentity("RANK_TRENDS_TRIGGER")
				.withSchedule(scheduleBuilder)
				.build();
	}

}

